package com.example.service.imp;

import com.example.bean.Depart;
import com.example.repository.DepartRepository;
import com.example.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author 徐文祥
 * @since 2023/12/07 00:56
 */
@Service
public class DepartServiceImpl implements DepartService {

    @Autowired
    private DepartRepository departRepository;

    @Override
    public boolean savaDepart(Depart depart) {
        Depart save = departRepository.save(depart);
        return save != null;
    }

    @Override
    public boolean deleteDepartById(Integer id) {
        if (departRepository.existsById(id)) {
            departRepository.deleteById(id);
            return true;
        }
        return false;

    }

    @Override
    public boolean modifyDepart(Depart depart) {
        Depart save = departRepository.save(depart);
        return save != null;
    }

    @Override
    public Depart getDepartById(Integer id) {
        if(departRepository.existsById(id)){
            return departRepository.getReferenceById(id);
        }
        return  new Depart();
    }

    @Override
    public List<Depart> getAllDepart() {
        return departRepository.findAll();
    }
}
